package com.tyler.service;

import com.spring.BeanPostProcessor;
import com.spring.Component;

import java.lang.reflect.Field;

@Component
public class TylerValueBeanPostProcessor implements BeanPostProcessor {

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws IllegalAccessException {
        for (Field field : bean.getClass().getDeclaredFields()) {
            if (field.isAnnotationPresent(TylerValue.class)) {
                field.setAccessible(true);
                field.set(bean, field.getAnnotation(TylerValue.class).value());
            }
        }
        return bean;
    }
}
